package com.xuyuan.spring.event;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

@Component
public class CutomEvenListener implements ApplicationListener<CustomMyEvent> {

    @Autowired
    private ObjectMapper mapper;

    @Override
    public void onApplicationEvent(CustomMyEvent event) {
        JsonNode jsonNode = mapper.convertValue(event.getSource(), JsonNode.class);
        System.out.println(jsonNode.get("email").asText() + jsonNode.get("message").asText());
        System.out.println("CustomMyEvent");
    }
}
